package com.cypress.dms.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cypress.dms.entity.Document;
import com.cypress.dms.service.DocumentService;

 /**
 * 文檔主表;(document)表控制层
 * @author : 
 * @date : 2025-9-28
 */
@RestController
@RequestMapping("/document")
public class DocumentController{
    
    @Autowired
    private DocumentService documentService;
    
    /** 
     * 通过ID查询单条数据 
     *
     * @param id 主键
     * @return 实例对象
     */
	@GetMapping("/queryById")
    public ResponseEntity<Document> queryById(Long id){
        return ResponseEntity.ok(documentService.getById(id));
    }
    
    /** 
     * 新增数据
     *
     * @param document 实例对象
     * @return 实例对象
     */
    @PostMapping("/add")
    public ResponseEntity<Document> add(Document document){
        documentService.save(document);
        return ResponseEntity.ok(document);
    }
    
    /** 
     * 更新数据
     *
     * @param document 实例对象
     * @return 实例对象
     */
    @PostMapping("/update")
    public ResponseEntity<Document> update(Document document){
        documentService.updateById(document);
        return ResponseEntity.ok(document);
    }
    
    /** 
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @PostMapping("/deleteById")
    public ResponseEntity<Boolean> deleteById(Long id){
        return ResponseEntity.ok(documentService.removeById(id));
    }
}